import PlayerType from "./enum/player";
import Boss from "./Boss";
import BossType from "./enum/boss";
const { ccclass, property } = cc._decorator;

@ccclass
export default class CPlayer extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    @property(cc.AudioClip)
    skillAudio: cc.AudioClip

    @property(cc.AudioClip)
    pugongAudio: cc.AudioClip


    @property(Boss)
    boss: Boss

    AudioSource: cc.AudioSource
    anim: sp.Skeleton
    aniName
    bossSrcipt
    onLoad() {
        this.anim = this.node.getComponent(sp.Skeleton)
        this.anim.animation = PlayerType.playerWait

        this.anim.setCompleteListener(() => {

            if (this.aniName == PlayerType.over) {

            } else if (this.aniName == PlayerType.attack_r || this.aniName == PlayerType.attack_y) {
                this.anim.animation = PlayerType.playerWait
            } else if (this.aniName == PlayerType.playerSkill) {
            }
            this.aniName = PlayerType.playerWait
            this.anim.animation = PlayerType.playerWait
        })



        //音频
        this.AudioSource = this.node.getComponent(cc.AudioSource)
    }



    start() {
        // 注册
    }



    playAudio(audioClip: cc.AudioClip, isLoop) {
        this.AudioSource.clip = audioClip
        if (isLoop) {
            this.AudioSource.loop = true
        }
        this.AudioSource.play()
    }
    setAni(aniName) {
        this.aniName = aniName
        this.anim.animation = this.aniName
        this.changeNodeStyle(aniName)
    }

    changeNodeStyle(aniName) {

        switch (aniName) {
            case PlayerType.attack_r:
                this.playAudio(this.pugongAudio, false)
                break;
            case PlayerType.attack_y:
                this.playAudio(this.pugongAudio, false)
                break;
            case PlayerType.playerSkill:
                this.playAudio(this.skillAudio, false)
                break;
            default:
                break;
        }

    }
    // update (dt) {}
}
